Ext.onReady(function() {

  	
	var win = new Ext.Window({
		width: 400,
		height: 260,
		items: [userForm],
		modal: true, //模态
		resizable: false, //禁制调整窗口大小
		closeAction: 'hide' //不销毁form对象，只是隐藏
	});
  
  var userForm = new Ext.FormPanel({
   id: 'imageform',
   labelWidth: 80, 
   labelAlign : 'right',
   border : false,
   fileUpload: true,
   applyTo: 'user_div1',
   bodyStyle : 'padding:10px 8px 8px 8px;',
   items:[{
             xtype: 'fieldset',
             title: '设置头像',
             collapsible: true,
             labelWidth: 69,
             collapsed: true,
             layout:'form',
             items: [{
              xtype: 'fileuploadfield',
                 id: 'upload',
                 name: 'upload',
                 emptyText: '选择相片地址',
                 fieldLabel: '上传路径',
                 buttonText: '',
                 width:440,
                 buttonCfg: {
                     iconCls: 'upload-avatar'
                 },
                 anchor : '96%'
             },{
              border:false,
                 layout:'form',
                 fieldLabel : "预览图片",      
                 items:[
                      {
                     xtype:'panel',
                     border:false,
                     layout:'column',
                     items:[{
                       xtype : 'box',      
                       id : 'browseImage',   
                       columnWidth:.35,
                       bodyStyle:'padding:10px 10px 10px 10px;',
                       autoEl : {   
                           width : 102,   
                           height : 125,   
                           tag : 'img',     
                           src : avatarurl
                       }  
                     },{
                     columnWidth:.5,
                     labelAlign :'left',
                     border:false,
                     buttonAlign:'center',
                     bodyStyle:'margin-left:10px;padding:5px',
                     items:[{
              xtype : 'label',
              fieldLabel:'',
                 html: '<ul><li>1、图片格式只能是jpg格式。</li></ul><br/>'
                     },{
              xtype : 'label',
              fieldLabel:'',
                 html: '<ul><li>2、图片大小不超过300K。</li></ul><br/>'
                    },{
              xtype : 'label',
              fieldLabel:'',
              html: '<ul><li>3、图片默认分辨率为102*125。</li></ul><br/>'
                    }] ,
                    buttons:[{
         xtype : 'button',
         fieldLabel:'',
         text:'上传头像',
         handler: function(){
           var file_path = Ext.getCmp('upload').getValue();
           var str = file_path.substr(file_path.lastIndexOf('.')+1,file_path.length);
           if(str!='JPG'&&str!='jpg'){
            Ext.Msg.alert('错误', "上传的图像只能是jpg格式！"); 
            return false;
           }       
           if(imageform.getForm().isValid()){
            imageform.getForm().submit({
                            url: '/SchoolManageSystem/upLoadAvatar.do',
                           success:function(form, action){   
                               var isSuc = action.result.success;
                               var message = action.result.message;   
                               var image_url = "/SchoolManageSystem"+ action.result.avatarurl;   
                              if(isSuc=='true'){
                                     Ext.Msg.alert('消息', message);
                              }else{
                                     Ext.Msg.alert('错误', message);   
                               }
                               Ext.getCmp("browseImage").getEl().dom.src=image_url;
                          },   
                          failure:function(form, action){   
                              var isSuc = action.result.success;
                              var message = action.result.message;  
                              if(isSuc=='true'){
                                   Ext.Msg.alert('消息', message);
                              }else{
                                   Ext.Msg.alert('错误', message);   
                              }
                                   Ext.getCmp("browseImage").getEl().dom.src=image_url;
                          }   
                        });
                       }
                   }
                     }
                 ]
                     }]
                  
                 }]
            }]
   }]
  })
  })